Java Code Examples for com.microsoft.azure.storage.blob.CloudBlobContainer#createIfNotExists()
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlobContainer#createIfNotExists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureConnectionManager.java From sunbird-lms-service with MIT License | 7 votes |
/** * This method will provide Azure CloudBlobContainer object or in case of error it will provide * null; * * @param containerName String * @return CloudBlobContainer or null */ public static CloudBlobContainer getContainer(String containerName, boolean isPublicAccess) { try { CloudBlobClient cloudBlobClient = getBlobClient(); // Get a reference to a container , The container name must be lower case CloudBlobContainer container = cloudBlobClient.getContainerReference(containerName.toLowerCase(Locale.ENGLISH)); // Create the container if it does not exist. boolean response = container.createIfNotExists(); ProjectLogger.log("container creation done if not exist==" + response); // Create a permissions object. if (isPublicAccess) { BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Include public access in the permissions object. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the permissions on the container. container.uploadPermissions(containerPermissions); } return container; } catch (Exception e) { ProjectLogger.log(e.getMessage(), e); } return null; }
Example 2
Source File: AzureResource.java From arcusplatform with Apache License 2.0 | 7 votes |
@Override public InputStream open() throws IOException { try { CloudBlobContainer blobContainer = blobClient.getContainerReference(container); blobContainer.createIfNotExists(); CloudBlockBlob blockBlob = blobContainer.getBlockBlobReference(blob); if (blockBlob.exists()) { return blockBlob.openInputStream(); } else { throw new IOException("Blob does not exist: " + container + ", " + blob); } } catch (Exception e) { throw new IOException("Unable to initialize blob: " + container + ", " + blob, e); } }
Example 3
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 7 votes |
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient, String accountName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient.getContainerReference("https://" + accountName + "/" + "$root"); container.createIfNotExists(); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); // Return a reference to the block blob object. return blob; }
Example 4
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 7 votes |
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient, String accountName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient.getContainerReference("https://" + accountName + "/" + "$root"); container.createIfNotExists(); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); // Return a reference to the block blob object. return blob; }
Example 5
Source File: AzureStorageDriver.java From dcos-cassandra-service with Apache License 2.0 | 7 votes |
private CloudBlobContainer getCloudBlobContainer(String accountName, String accountKey, String containerName) { CloudBlobContainer container = null; if (StringUtils.isNotBlank(containerName)) { final String storageConnectionString = "DefaultEndpointsProtocol=https" + ";AccountName=" + accountName + ";AccountKey=" + accountKey; try { final CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString); CloudBlobClient serviceClient = account.createCloudBlobClient(); container = serviceClient.getContainerReference(containerName); container.createIfNotExists(); } catch (StorageException | URISyntaxException | InvalidKeyException e) { logger.error("Error connecting to container for account {} and container name {}", accountName, containerName, e); } } return container; }
Example 6
Source File: AzureSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateWasbFileSystem(SpiFileSystem fileSystem) throws URISyntaxException, InvalidKeyException, StorageException { CloudWasbView cloudFileSystem = (CloudWasbView) fileSystem.getCloudFileSystems().get(0); String accountName = cloudFileSystem.getAccountName(); String accountKey = cloudFileSystem.getAccountKey(); String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey; CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime()); try { containerReference.createIfNotExists(); containerReference.delete(); } catch (StorageException e) { if (e.getCause() instanceof UnknownHostException) { throw new CloudConnectorException("The provided account does not belong to a valid storage account"); } } }
Example 7
Source File: BlobBasics.java From storage-blob-java-getting-started with MIT License | 6 votes |
/** * Creates and returns a container for the sample application to use. * * @param blobClient CloudBlobClient object * @param containerName Name of the container to create * @return The newly created CloudBlobContainer object * * @throws StorageException * @throws RuntimeException * @throws IOException * @throws URISyntaxException * @throws IllegalArgumentException * @throws InvalidKeyException * @throws IllegalStateException */ private static CloudBlobContainer createContainer(CloudBlobClient blobClient, String containerName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException { // Create a new container CloudBlobContainer container = blobClient.getContainerReference(containerName); try { if (container.createIfNotExists() == false) { throw new IllegalStateException(String.format("Container with name \"%s\" already exists.", containerName)); } } catch (StorageException s) { if (s.getCause() instanceof java.net.ConnectException) { System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator."); } throw s; } return container; }
Example 8
Source File: ManageLinuxWebAppStorageAccountConnection.java From azure-libraries-for-java with MIT License | 6 votes |
private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) { try { CloudStorageAccount account = CloudStorageAccount.parse(connectionString); // Create a blob service client CloudBlobClient blobClient = account.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(containerName); container.createIfNotExists(); BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Include public access in the permissions object containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the permissions on the container container.uploadPermissions(containerPermissions); return container; } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new RuntimeException(e); } }
Example 9
Source File: ManageWebAppStorageAccountConnection.java From azure-libraries-for-java with MIT License | 6 votes |
private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) { try { CloudStorageAccount account = CloudStorageAccount.parse(connectionString); // Create a blob service client CloudBlobClient blobClient = account.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(containerName); container.createIfNotExists(); BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Include public access in the permissions object containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the permissions on the container container.uploadPermissions(containerPermissions); return container; } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new RuntimeException(e); } }
Example 10
Source File: AzureSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateAdlsGen2FileSystem(SpiFileSystem fileSystem) throws URISyntaxException, InvalidKeyException, StorageException { CloudAdlsGen2View cloudFileSystem = (CloudAdlsGen2View) fileSystem.getCloudFileSystems().get(0); String accountName = cloudFileSystem.getAccountName(); String accountKey = cloudFileSystem.getAccountKey(); String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=core.windows.net"; CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime()); try { containerReference.createIfNotExists(); containerReference.delete(); } catch (StorageException e) { if (e.getCause() instanceof UnknownHostException) { throw new CloudConnectorException("The provided account does not belong to a valid storage account"); } } }
Example 11
Source File: AzureStorageBlobService.java From components with Apache License 2.0 | 5 votes |
/** * This method create an azure container if it doesn't exist and set it access policy * * @param containerName : the name of the container to be created * @return true if the container was created, false otherwise */ public boolean createContainerIfNotExist(final String containerName, final BlobContainerPublicAccessType accessType) throws StorageException, URISyntaxException, InvalidKeyException { CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName); boolean containerCreated; try { containerCreated = cloudBlobContainer .createIfNotExists(accessType, null, AzureStorageUtils.getTalendOperationContext()); } catch (StorageException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.CONTAINER_BEING_DELETED)) { throw e; } LOGGER.warn(messages.getMessage("error.CONTAINER_BEING_DELETED", containerName)); // wait 40 seconds (min is 30s) before retrying. // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-container try { Thread.sleep(40000); } catch (InterruptedException eint) { LOGGER.error(messages.getMessage("error.InterruptedException")); throw new ComponentException(eint); } containerCreated = cloudBlobContainer .createIfNotExists(accessType, null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug(messages.getMessage("debug.ContainerCreated", containerName)); } return containerCreated; }
Example 12
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 5 votes |
private static CloudBlobContainer getStorageContainer(CloudBlobClient client, String container) { try { CloudBlobContainer cnt = client.getContainerReference(container); cnt.createIfNotExists(); return cnt; } catch (Exception ex) { VIDEO_STORAGE_AZURE_NO_CONTAINER.inc(); throw new RuntimeException(ex); } }
Example 13
Source File: AzureStorageHelper.java From azure-gradle-plugins with MIT License | 5 votes |
public static String uploadFileAsBlob(final File fileToUpload, final CloudStorageAccount storageAccount, final String containerName, final String blobName) throws Exception { final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName); blobContainer.createIfNotExists(BlobContainerPublicAccessType.BLOB, null, null); final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName); blob.upload(new FileInputStream(fileToUpload), fileToUpload.length()); return blob.getUri().toString(); }
Example 14
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception { // Create a container if it does not exist. container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Create a UTC Gregorian calendar value. GregorianCalendar calendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); // Specify the current time as the start time for the shared access // signature. // calendar.setTime(new Date()); sasPolicy.setSharedAccessStartTime(calendar.getTime()); // Use the start time delta one hour as the end time for the shared // access signature. calendar.add(Calendar.HOUR, 10); sasPolicy.setSharedAccessExpiryTime(calendar.getTime()); if (readonly) { // Set READ permissions sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST)); } else { // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST)); } // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF); container.uploadPermissions(containerPermissions); // Create a shared access signature for the container. String sas = container.generateSharedAccessSignature(sasPolicy, null); // HACK: when the just generated SAS is used straight away, we get an // authorization error intermittently. Sleeping for 1.5 seconds fixes that // on my box. Thread.sleep(1500); // Return to caller with the shared access signature. return sas; }
Example 15
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient .getContainerReference(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example 16
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception { // Create a container if it does not exist. container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Create a UTC Gregorian calendar value. GregorianCalendar calendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); // Specify the current time as the start time for the shared access // signature. // calendar.setTime(new Date()); sasPolicy.setSharedAccessStartTime(calendar.getTime()); // Use the start time delta one hour as the end time for the shared // access signature. calendar.add(Calendar.HOUR, 10); sasPolicy.setSharedAccessExpiryTime(calendar.getTime()); if (readonly) { // Set READ permissions sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST)); } else { // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST)); } // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF); container.uploadPermissions(containerPermissions); // Create a shared access signature for the container. String sas = container.generateSharedAccessSignature(sasPolicy, null); // HACK: when the just generated SAS is used straight away, we get an // authorization error intermittently. Sleeping for 1.5 seconds fixes that // on my box. Thread.sleep(1500); // Return to caller with the shared access signature. return sas; }
Example 17
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient .getContainerReference(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example 18
Source File: QueryMetricsAndActivityLogs.java From azure-libraries-for-java with MIT License | 4 votes |
private static void addBlobTransactions(String storageConnectionString) throws IOException, URISyntaxException, InvalidKeyException, StorageException { // Get the script to upload // InputStream scriptFileAsStream = QueryMetricsAndActivityLogs .class .getResourceAsStream("/install_apache.sh"); // Get the size of the stream // int fileSize; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[256]; int bytesRead; while ((bytesRead = scriptFileAsStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } fileSize = outputStream.size(); outputStream.close(); // Upload the script file as block blob // CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString); CloudBlobClient cloudBlobClient = account.createCloudBlobClient(); CloudBlobContainer container = cloudBlobClient.getContainerReference("scripts"); container.createIfNotExists(); ServiceProperties serviceProps = cloudBlobClient.downloadServiceProperties(); // configure Storage logging and metrics LoggingProperties logProps = new LoggingProperties(); logProps.setLogOperationTypes(EnumSet.of(LoggingOperations.READ, LoggingOperations.WRITE)); logProps.setRetentionIntervalInDays(2); logProps.setVersion("1.0"); serviceProps.setLogging(logProps); MetricsProperties metricProps = new MetricsProperties(); metricProps.setMetricsLevel(MetricsLevel.SERVICE_AND_API); metricProps.setRetentionIntervalInDays(2); metricProps.setVersion("1.0"); serviceProps.setHourMetrics(metricProps); serviceProps.setMinuteMetrics(metricProps); // Set the default service version to be used for anonymous requests. serviceProps.setDefaultServiceVersion("2015-04-05"); // Set the service properties. cloudBlobClient.uploadServiceProperties(serviceProps); CloudBlockBlob blob = container.getBlockBlobReference("install_apache.sh"); blob.upload(scriptFileAsStream, fileSize); // give sometime for the infrastructure to process the records and fit into time grain. SdkContext.sleep(6 * 60000); }
Example 19
Source File: TestBatchAI.java From azure-libraries-for-java with MIT License | 4 votes |
@Override public BatchAIWorkspace createResource(BatchAIWorkspaces workspaces) throws Exception { final String groupName = SdkContext.randomResourceName("rg", 10); final String workspaceName = SdkContext.randomResourceName("ws", 10); final String vnetName = SdkContext.randomResourceName("vnet", 15); final String saName = SdkContext.randomResourceName("cluster", 15); final String shareName = "myfileshare"; final String shareMountPath = "azurefileshare"; final String blobFileSystemPath = "myblobsystem"; final String containerName = "mycontainer"; final String userName = "tirekicker"; final String subnetName = "MySubnet"; String storageAccountKey; String fileShareUri; BatchAIWorkspace workspace = workspaces.define(workspaceName) .withRegion(region) .withNewResourceGroup(groupName) .create(); if (isPlaybackMode()) { storageAccountKey = "dummy_key"; fileShareUri = "dummy_uri"; } else { storageAccountKey = ensureStorageAccount(storageAccounts, saName, groupName, shareName); String connectionString = String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s", saName, storageAccountKey); CloudFileShare cloudFileShare = CloudStorageAccount.parse(String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net", saName, storageAccountKey)) .createCloudFileClient() .getShareReference(shareName); cloudFileShare.create(); CloudStorageAccount account = CloudStorageAccount.parse(connectionString); CloudBlobClient cloudBlobClient = account.createCloudBlobClient(); CloudBlobContainer container = cloudBlobClient.getContainerReference(containerName); container.createIfNotExists(); fileShareUri = cloudFileShare.getStorageUri().getPrimaryUri().toString(); } Network network = networks.define(vnetName) .withRegion(region) .withExistingResourceGroup(groupName) .withAddressSpace("192.168.0.0/16") .withSubnet(subnetName, "192.168.200.0/24") .create(); BatchAICluster cluster = workspace.clusters().define(clusterName) .withVMSize(VirtualMachineSizeTypes.STANDARD_D1_V2.toString()) .withUserName(userName) .withPassword("MyPassword") .withAutoScale(1, 1) .withLowPriority() .defineSetupTask() .withCommandLine("echo Hello World!") .withStdOutErrPath("./outputpath") .attach() .defineAzureFileShare() .withStorageAccountName(saName) .withAzureFileUrl(fileShareUri) .withRelativeMountPath(shareMountPath) .withAccountKey(storageAccountKey) .attach() .defineAzureBlobFileSystem() .withStorageAccountName(saName) .withContainerName(containerName) .withRelativeMountPath(blobFileSystemPath) .withAccountKey(storageAccountKey) .attach() .withVirtualMachineImage("microsoft-ads", "linux-data-science-vm-ubuntu", "linuxdsvmubuntu") .withSubnet(network.id(), subnetName) .withAppInsightsComponentId("appinsightsId") .withInstrumentationKey("appInsightsKey") .create(); printBatchAICluster(cluster); Assert.assertEquals("resizing", cluster.allocationState().toString()); Assert.assertEquals(userName, cluster.adminUserName()); Assert.assertEquals(VmPriority.LOWPRIORITY, cluster.vmPriority()); Assert.assertEquals(1, cluster.nodeSetup().mountVolumes().azureFileShares().size()); Assert.assertEquals(shareMountPath, cluster.nodeSetup().mountVolumes().azureFileShares().get(0).relativeMountPath()); Assert.assertEquals(1, cluster.nodeSetup().mountVolumes().azureBlobFileSystems().size()); Assert.assertEquals(blobFileSystemPath, cluster.nodeSetup().mountVolumes().azureBlobFileSystems().get(0).relativeMountPath()); Assert.assertEquals(network.id() + "/subnets/" + subnetName, cluster.subnet().id()); Assert.assertEquals("appinsightsId", cluster.nodeSetup().performanceCountersSettings().appInsightsReference().component().id()); Assert.assertEquals("linux-data-science-vm-ubuntu", cluster.virtualMachineConfiguration().imageReference().offer()); return workspace; }
Example 20
Source File: MaximumExecutionTimeTests.java From azure-storage-android with Apache License 2.0 | 4 votes |
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) public void testMaximumExecutionTimeBlobByteArray() throws URISyntaxException, StorageException, IOException { int length = 10 * 1024 * 1024; byte[] uploadBuffer = BlobTestHelper.getRandomBuffer(length); byte[] downloadBuffer = new byte[length]; // set a delay in sending request OperationContext opContext = new OperationContext(); setDelay(opContext, 2500); // set the maximum execution time BlobRequestOptions options = new BlobRequestOptions(); options.setMaximumExecutionTimeInMs(2000); CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(generateRandomName("container")); String blobName = "testBlob"; final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName); ByteArrayInputStream inputStream = new ByteArrayInputStream(uploadBuffer); try { container.createIfNotExists(); blockBlobRef.upload(inputStream, length); assertTrue(blockBlobRef.exists()); try { blockBlobRef.downloadToByteArray(downloadBuffer, 0, null, options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); } } finally { inputStream.close(); container.deleteIfExists(); } }