static boolean isBlobAlreadyExistsConflict(StorageException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT && StorageErrorCodeStrings.BLOB_ALREADY_EXISTS.equals(e.getErrorCode())) { return true; } return false; }
private void doCreateAppendBlob(CloudAppendBlob client, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating an append blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); try { client.createOrReplace(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } catch (StorageException ex) { if (ex.getHttpStatusCode() != 409) { throw ex; } } ExchangeUtil.getMessageForResponse(exchange) .setHeader(BlobServiceConstants.APPEND_BLOCK_CREATED, Boolean.TRUE); }
@Override protected int poll() throws Exception { Exchange exchange = super.getEndpoint().createExchange(); try { LOG.trace("Retrieving a message"); retrieveMessage(exchange); super.getAsyncProcessor().process(exchange); return 1; } catch (StorageException ex) { if (404 == ex.getHttpStatusCode()) { return 0; } else { throw ex; } } }
@Override protected int poll() throws Exception { Exchange exchange = super.getEndpoint().createExchange(); try { LOG.trace("Getting the blob content"); getBlob(exchange); super.getAsyncProcessor().process(exchange); return 1; } catch (StorageException ex) { if (404 == ex.getHttpStatusCode()) { return 0; } else { throw ex; } } }
private void doCreatePageBlob(CloudPageBlob client, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); Long pageSize = getPageBlobSize(exchange); try { client.create(pageSize, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } catch (StorageException ex) { if (ex.getHttpStatusCode() != 409) { throw ex; } } ExchangeUtil.getMessageForResponse(exchange) .setHeader(BlobServiceConstants.PAGE_BLOCK_CREATED, Boolean.TRUE); }
public void testClearMessagesNotFound() throws StorageException, URISyntaxException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.clear(); fail(); } catch (StorageException ex) { assertEquals("Expected 404 Exception", ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testPeekMessagesNonFound() throws StorageException, URISyntaxException { CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.peekMessages(1); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadataNotFound() throws URISyntaxException, StorageException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.uploadMetadata(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDownloadAttributesNotFound() throws StorageException, URISyntaxException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.downloadAttributes(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testPeekMessageNonExistingQueue() throws StorageException, URISyntaxException { CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.peekMessage(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testRetrieveMessageNonExistingQueue() throws StorageException, URISyntaxException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.retrieveMessage(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testRetrieveMessagesNonFound() throws StorageException, URISyntaxException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.retrieveMessages(1); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerMissingBlob() throws StorageException, URISyntaxException, IOException { this.container.create(); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("missing"); try { this.container.getBlobReferenceFromServer(blobName); fail("Get reference from server should fail."); } catch (StorageException ex) { assertEquals(404, ex.getHttpStatusCode()); } }
/** * Try to upload with a bad lease * * @param length * @param blobRef * @throws IOException */ private void tryUploadWithBadLease(final int length, final CloudBlob blobRef, final AccessCondition leaseCondition, final String expectedError) throws IOException { try { blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition, null, null); fail("Did not throw expected exception"); } catch (final StorageException ex) { assertEquals(ex.getHttpStatusCode(), 412); assertEquals(ex.getErrorCode(), expectedError); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testAddMessageToNonExistingQueue() throws StorageException, URISyntaxException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final CloudQueue queue = qClient.getQueueReference(QueueTestHelper.generateRandomQueueName()); String messageContent = "messagetest"; CloudQueueMessage message1 = new CloudQueueMessage(messageContent); try { queue.addMessage(message1); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
private void testBatchDelete(TableRequestOptions options) throws StorageException { Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); // insert entity this.table.execute(TableOperation.insert(ref), options, null); TableBatchOperation batch = new TableBatchOperation(); batch.delete(ref); ArrayList<TableResult> delResults = this.table.execute(batch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } try { this.table.execute(batch, options, null); fail(); } catch (StorageException ex) { assertEquals(ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testDeleteNonExistingQueue() throws URISyntaxException, StorageException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); final OperationContext existQueueContext1 = new OperationContext(); assertTrue(!queue.exists(null, existQueueContext1)); assertEquals(existQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); try { queue.delete(); fail("Queue delete no exsiting queue. "); } catch (StorageException ex) { assertEquals("Expected 404 Exception", ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } }
/** * Try to create a share after it is created * * @throws StorageException */ @Test public void testCloudFileShareCreate() throws StorageException { this.share.create(); assertTrue(this.share.exists()); try { this.share.create(); fail("Share already existed but was created anyway."); } catch (StorageException e) { assertEquals(e.getErrorCode(), "ShareAlreadyExists"); assertEquals(e.getHttpStatusCode(), 409); assertEquals(e.getMessage(), "The specified share already exists."); } }
private static void testContainerDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); MultiLocationTestHelper helper = new MultiLocationTestHelper(container.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); container.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); BlobRequestOptions options = new BlobRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { container.downloadAttributes(null, options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
@Test public void testOpenOutputStreamNoArgs() throws URISyntaxException, StorageException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob pageBlob = this.container.getPageBlobReference(blobName); try { pageBlob.openWriteExisting(); } catch (StorageException ex) { assertEquals("The specified blob does not exist.", ex.getMessage()); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } pageBlob.openWriteNew(1024); pageBlob.openWriteExisting(); CloudPageBlob pageBlob2 = this.container.getPageBlobReference(blobName); pageBlob2.downloadAttributes(); assertEquals(1024, pageBlob2.getProperties().getLength()); assertEquals(BlobType.PAGE_BLOB, pageBlob2.getProperties().getBlobType()); }