com.microsoft.azure.storage.RetryNoRetry Java Examples

The following examples show how to use com.microsoft.azure.storage.RetryNoRetry. 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: TableBatchOperationTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
@Test
// don't need the category secondary as the request will fail before being sent
public void testBatchSecondaryWriteShouldThrow() {
    // create batch with an insert
    Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata");
    TableOperation op = TableOperation.insert(baseEntity);

    TableBatchOperation batch = new TableBatchOperation();
    batch.add(op);

    // should not be able to make a request to secondary as there are writes
    try {
        TableRequestOptions options = new TableRequestOptions();
        options.setLocationMode(LocationMode.SECONDARY_ONLY);
        options.setRetryPolicyFactory(new RetryNoRetry());
        this.table.execute(batch, options, null);
        fail("Should not be able to make a request to secondary as there are writes.");
    }
    catch (StorageException e) {
        assertEquals(IllegalArgumentException.class, e.getCause().getClass());
        assertEquals(SR.PRIMARY_ONLY_COMMAND, e.getCause().getMessage());
    }
}
 
Example #2
Source File: TableBatchOperationTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
@Test
@Category(SecondaryTests.class)
public void testBatchSecondaryNoWrite() throws StorageException {
    // create and insert an entity
    Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata");
    this.table.execute(TableOperation.insert(ref));

    // create a batch and add a query for this entity
    TableBatchOperation batch = new TableBatchOperation();
    TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass());
    batch.add(queryOp);

    // should be able to make a request to secondary as there are no writes
    TableRequestOptions options = new TableRequestOptions();
    options.setLocationMode(LocationMode.SECONDARY_ONLY);
    options.setRetryPolicyFactory(new RetryNoRetry());
    this.table.execute(batch, options, null);
}
 
Example #3
Source File: CloudPageBlobTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
public void testPageBlobInputStream() throws URISyntaxException, StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
    final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.upload(sourceStream, blobLength, null, options, operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
Example #4
Source File: CloudAppendBlobTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppendBlobInputStream() throws URISyntaxException,
        StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper
            .generateRandomBlobNameWithPrefix("testblob");
    final CloudAppendBlob blobRef = this.container
            .getAppendBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.upload(sourceStream, blobLength, null, options,
            operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
Example #5
Source File: CloudBlockBlobTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlobInputStream() throws URISyntaxException, StorageException, IOException {
    final int blobLength = 16 * 1024;
    final Random randGenerator = new Random();
    String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
    final CloudBlockBlob blobRef = this.container.getBlockBlobReference(blobName);

    final byte[] buff = new byte[blobLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final BlobRequestOptions options = new BlobRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setStoreBlobContentMD5(true);
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    blobRef.uploadFullBlob(sourceStream, blobLength, null, options, operationContext);

    BlobInputStream blobStream = blobRef.openInputStream();

    for (int i = 0; i < blobLength; i++) {
        int data = blobStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, blobStream.read());

    blobRef.delete();
}
 
Example #6
Source File: CloudFileTests.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test file input stream.
 * 
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 */
@Test
public void testCloudFileInputStream() throws URISyntaxException, StorageException, IOException {
    final int fileLength = 16 * 1024;
    final Random randGenerator = new Random();
    String fileName = FileTestHelper.generateRandomFileName();
    final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName);

    final byte[] buff = new byte[fileLength];
    randGenerator.nextBytes(buff);
    buff[0] = -1;
    buff[1] = -128;
    final ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff);

    final FileRequestOptions options = new FileRequestOptions();
    final OperationContext operationContext = new OperationContext();
    options.setTimeoutIntervalInMs(90000);
    options.setRetryPolicyFactory(new RetryNoRetry());
    fileRef.upload(sourceStream, fileLength, null, options, operationContext);

    com.microsoft.azure.storage.file.FileInputStream fileStream = fileRef.openRead();

    for (int i = 0; i < fileLength; i++) {
        int data = fileStream.read();
        assertTrue(data >= 0);
        assertEquals(buff[i], (byte) data);
    }

    assertEquals(-1, fileStream.read());

    fileRef.delete();
}
 
Example #7
Source File: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * If we're asked by unit tests to not retry, set the retry policy factory in
 * the client accordingly.
 */
private void suppressRetryPolicyInClientIfNeeded() {
  if (suppressRetryPolicy) {
    storageInteractionLayer.setRetryPolicyFactory(new RetryNoRetry());
  }
}
 
Example #8
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * If we're asked by unit tests to not retry, set the retry policy factory in
 * the client accordingly.
 */
private void suppressRetryPolicyInClientIfNeeded() {
  if (suppressRetryPolicy) {
    storageInteractionLayer.setRetryPolicyFactory(new RetryNoRetry());
  }
}
 
Example #9
Source File: TableTests.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
@Test
@Category(SlowTests.class)
public void testTableSas() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {
    CloudTableClient tClient = TableTestHelper.createCloudTableClient();

    // use capital letters to make sure SAS signature converts name to lower case correctly
    String name = "CAPS" + TableTestHelper.generateRandomTableName();
    CloudTable table = tClient.getTableReference(name);
    table.create();

    TablePermissions expectedPermissions = new TablePermissions();
    String identifier = UUID.randomUUID().toString();
    // Add a policy, check setting and getting.
    SharedAccessTablePolicy policy1 = new SharedAccessTablePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -10);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());

    policy1.setPermissions(EnumSet.of(SharedAccessTablePermissions.ADD, SharedAccessTablePermissions.QUERY,
            SharedAccessTablePermissions.UPDATE, SharedAccessTablePermissions.DELETE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    table.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    // Insert 500 entities in Batches to query
    for (int i = 0; i < 5; i++) {
        TableBatchOperation batch = new TableBatchOperation();

        for (int j = 0; j < 100; j++) {
            Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i));
            ent.setRowKey(String.format("%06d", j));
            batch.insert(ent);
        }

        table.execute(batch);
    }

    String sasString = table.generateSharedAccessSignature(policy1, null, "javatables_batch_0", "0",
            "javatables_batch_9", "9");
    CloudTableClient tableClientFromPermission = new CloudTableClient(tClient.getEndpoint(),
            new StorageCredentialsSharedAccessSignature(sasString));

    CloudTable policySasTable = tableClientFromPermission.getTableReference(name);

    // do not give the client and check that the new table's client has the correct perms
    CloudTable tableFromUri = new CloudTable(PathUtility.addToQuery(table.getStorageUri(), table
            .generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // create credentials from sas
    StorageCredentials creds = new StorageCredentialsSharedAccessSignature(
            table.generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0",
                    "javatables_batch_9", "9"));
    CloudTableClient tableClient = new CloudTableClient(policySasTable.getServiceClient().getStorageUri(), creds);

    // set some arbitrary settings to make sure they are passed on
    tableClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    tableClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    tableClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata);
    tableClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    tableFromUri = tableClient.getTableReference(table.getName());
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    assertEquals(tableClient.getDefaultRequestOptions().getLocationMode(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getLocationMode());
    assertEquals(tableClient.getDefaultRequestOptions().getTimeoutIntervalInMs(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTimeoutIntervalInMs());
    assertEquals(tableClient.getDefaultRequestOptions().getTablePayloadFormat(), tableFromUri.getServiceClient()
            .getDefaultRequestOptions().getTablePayloadFormat());
    assertEquals(tableClient.getDefaultRequestOptions().getRetryPolicyFactory().getClass(), tableFromUri
            .getServiceClient().getDefaultRequestOptions().getRetryPolicyFactory().getClass());
}
 
Example #10
Source File: CloudQueueTests.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
@Test
@Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class })
public void testQueueSAS() throws StorageException, URISyntaxException, InvalidKeyException, InterruptedException {
    this.queue.addMessage(new CloudQueueMessage("sas queue test"));
    QueuePermissions expectedPermissions;

    expectedPermissions = new QueuePermissions();
    // Add a policy, check setting and getting.
    SharedAccessQueuePolicy policy1 = new SharedAccessQueuePolicy();
    Calendar now = GregorianCalendar.getInstance();
    now.add(Calendar.MINUTE, -15);
    policy1.setSharedAccessStartTime(now.getTime());
    now.add(Calendar.MINUTE, 30);
    policy1.setSharedAccessExpiryTime(now.getTime());
    String identifier = UUID.randomUUID().toString();

    policy1.setPermissions(EnumSet.of(SharedAccessQueuePermissions.READ,
            SharedAccessQueuePermissions.PROCESSMESSAGES, SharedAccessQueuePermissions.ADD,
            SharedAccessQueuePermissions.UPDATE));
    expectedPermissions.getSharedAccessPolicies().put(identifier, policy1);

    this.queue.uploadPermissions(expectedPermissions);
    Thread.sleep(30000);

    CloudQueue identifierSasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(null, identifier)));

    identifierSasQueue.downloadAttributes();
    identifierSasQueue.exists();

    identifierSasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message1 = identifierSasQueue.retrieveMessage();
    identifierSasQueue.deleteMessage(message1);

    CloudQueue policySasQueue = new CloudQueue(PathUtility.addToQuery(this.queue.getUri(),
            this.queue.generateSharedAccessSignature(policy1, null)));
    policySasQueue.exists();
    policySasQueue.downloadAttributes();

    policySasQueue.addMessage(new CloudQueueMessage("message"), 20, 0, null, null);
    CloudQueueMessage message2 = policySasQueue.retrieveMessage();
    policySasQueue.deleteMessage(message2);

    // do not give the client and check that the new queue's client has the correct perms
    CloudQueue queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());

    // pass in a client which will have different permissions and check the sas permissions are used
    // and that the properties set in the old service client are passed to the new client
    CloudQueueClient queueClient = policySasQueue.getServiceClient();

    // set some arbitrary settings to make sure they are passed on
    queueClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
    queueClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000);
    queueClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry());

    queueFromUri = new CloudQueue(PathUtility.addToQuery(this.queue.getStorageUri(),
            this.queue.generateSharedAccessSignature(null, "readperm")));
    assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient()
            .getCredentials().getClass().toString());
}