@Test public void testAppendBlobMaxSizeCondition() throws URISyntaxException, StorageException, IOException { final int blobLength = 16 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); final CloudAppendBlob blobRef = this.container .getAppendBlobReference(blobName); final byte[] buff = BlobTestHelper.getRandomBuffer(blobLength); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff); // Max length position failure AccessCondition cond = new AccessCondition(); cond.setIfMaxSizeLessThanOrEqual(blobLength - 1L); try { blobRef.upload(sourceStream, blobLength, cond, null, null); fail("Expected IOException for exceeding the max size"); } catch (IOException ex) { assertEquals(SR.INVALID_BLOCK_SIZE, ex.getMessage()); } }
appendCondition.setLeaseID(accessCondition.getLeaseID()); appendCondition.setIfAppendPositionEqual(accessCondition.getIfAppendPositionEqual()); appendCondition.setIfMaxSizeLessThanOrEqual(accessCondition.getIfMaxSizeLessThanOrEqual());
appendCondition.setLeaseID(accessCondition.getLeaseID()); appendCondition.setIfAppendPositionEqual(accessCondition.getIfAppendPositionEqual()); appendCondition.setIfMaxSizeLessThanOrEqual(accessCondition.getIfMaxSizeLessThanOrEqual());
accessCondition.setIfMaxSizeLessThanOrEqual(1024*2+1L); sourceStream = new ByteArrayInputStream(buffer); blob.appendBlock(sourceStream, -1, accessCondition, null, null); accessCondition.setIfMaxSizeLessThanOrEqual(1024 - 1L); try { sourceStream = new ByteArrayInputStream(buffer);
cond.setIfMaxSizeLessThanOrEqual((long)blobLength);
accessCondition.setIfMaxSizeLessThanOrEqual(1024*2+1L); str = blob.openWriteExisting(accessCondition, null, null); str.write(buffer); accessCondition.setIfMaxSizeLessThanOrEqual(1024 - 1L); try { str = blob.openWriteExisting(accessCondition, null, null);