/** * Populates the default timeout and retry policy from client if they are not set. * * @param options * The input options to copy from when applying defaults * @param client * The {@link CloudQueueClient} service client to populate the * default values from. */ protected static final QueueRequestOptions populateAndApplyDefaults(QueueRequestOptions options, final CloudQueueClient client) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); QueueRequestOptions.populateRequestOptions(modifiedOptions, client.getDefaultRequestOptions()); QueueRequestOptions.applyDefaults(modifiedOptions); return modifiedOptions; }
@DoesServiceRequest private boolean exists(final boolean primaryOnly, QueueRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { opContext = new OperationContext(); } opContext.initialize(); options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient); return ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.existsImpl(primaryOnly, options), options.getRetryPolicyFactory(), opContext); }
/** * Assert that if strict mode is on, an encryption policy is specified. */ protected void assertPolicyIfRequired() { if (this.requireEncryption() != null && this.requireEncryption() && this.getEncryptionPolicy() == null) { throw new IllegalArgumentException(SR.ENCRYPTION_POLICY_MISSING_IN_STRICT_MODE); } } }
/** * Initializes a new instance of the QueueRequestOptions class as a copy of * another QueueRequestOptions instance. * * @param other * The {@link QueueRequestOptions} object to copy the values * from. */ public QueueRequestOptions(final QueueRequestOptions other) { super(other); if (other != null) { this.setEncryptionPolicy(other.getEncryptionPolicy()); } }
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient); options.assertPolicyIfRequired(); this.peekMessagesImpl(numberOfMessages, options), options.getRetryPolicyFactory(), opContext);
/** * Populates the default timeout and retry policy from client if they are not set. * * @param options * The input options to copy from when applying defaults * @param client * The {@link CloudQueueClient} service client to populate the * default values from. */ protected static final QueueRequestOptions populateAndApplyDefaults(QueueRequestOptions options, final CloudQueueClient client) { QueueRequestOptions modifiedOptions = new QueueRequestOptions(options); RequestOptions.populateRequestOptions(modifiedOptions, client.getDefaultRequestOptions(), true /* setStartTime */); QueueRequestOptions.applyDefaults(modifiedOptions); return modifiedOptions; }
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) public void testQueueMaximumExecutionTime() throws URISyntaxException, StorageException { OperationContext opContext = new OperationContext(); setDelay(opContext, 2500); // set the maximum execution time QueueRequestOptions options = new QueueRequestOptions(); options.setMaximumExecutionTimeInMs(2000); // set the location mode to secondary, secondary request should fail // so set the timeout low to save time failing (or fail with a timeout) options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); options.setTimeoutIntervalInMs(1000); CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference(generateRandomName("queue")); try { // 1. download attributes will fail as the queue does not exist // 2. the executor will attempt to retry as it is accessing secondary // 3. maximum execution time should prevent the retry from being made queue.downloadAttributes(options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); } }
private static void testQueueDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudQueueClient client = TestHelper.createCloudQueueClient(); CloudQueue queue = client.getQueueReference(QueueTestHelper.generateRandomQueueName()); MultiLocationTestHelper helper = new MultiLocationTestHelper(queue.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); queue.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); QueueRequestOptions options = new QueueRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { queue.downloadAttributes(options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
QueueRequestOptions options = new QueueRequestOptions(); options.setLocationMode(LocationMode.PRIMARY_ONLY); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_ONLY); try { queue.createIfNotExists(options, context); options.setLocationMode(LocationMode.PRIMARY_ONLY); queue.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); queue.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); queue.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation());
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);
/** * Initializes a new instance of the <code>CloudQueueClient</code> class using the specified Queue service endpoint * and account credentials. * * @param baseUri * A {@link StorageUri} object that represents the Queue service endpoint used to create the * client. * @param credentials * A {@link StorageCredentials} object that represents the account credentials. */ public CloudQueueClient(final StorageUri baseUri, final StorageCredentials credentials) { super(baseUri, credentials); if (credentials == null || credentials.getClass().equals(StorageCredentialsAnonymous.class)) { throw new IllegalArgumentException(SR.STORAGE_CREDENTIALS_NULL_OR_ANONYMOUS); } QueueRequestOptions.applyDefaults(this.defaultRequestOptions); }
String result = null; if (options.getEncryptionPolicy() != null) String encryptedMessageString = options.getEncryptionPolicy().encryptMessage(this.getMessageContentAsByte());
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient); options.assertPolicyIfRequired(); options.getRetryPolicyFactory(), opContext);
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);
/** * Populates any null fields in the first requestOptions object with values from the second requestOptions object. * * @param modifiedOptions * A {@link QueueRequestOptions} object from which to copy options. * @param clientOptions * A {@link QueueRequestOptions} object where options will be copied. * * @return A {@link RequestOptions} object. */ private static void populateRequestOptions(QueueRequestOptions modifiedOptions, final QueueRequestOptions clientOptions) { RequestOptions.populateRequestOptions(modifiedOptions, clientOptions, true); if (modifiedOptions.getEncryptionPolicy() == null) { modifiedOptions.setEncryptionPolicy(clientOptions.getEncryptionPolicy()); } }
/** * Initializes a new instance of the <code>CloudQueueClient</code> class using the specified Queue service endpoint * and account credentials. * * @param baseUri * A {@link StorageUri} object that represents the Queue service endpoint used to create the * client. * @param credentials * A {@link StorageCredentials} object that represents the account credentials. */ public CloudQueueClient(final StorageUri baseUri, final StorageCredentials credentials) { super(baseUri, credentials); if (credentials == null || credentials.getClass().equals(StorageCredentialsAnonymous.class)) { throw new IllegalArgumentException(SR.STORAGE_CREDENTIALS_NULL_OR_ANONYMOUS); } QueueRequestOptions.applyDefaults(this.defaultRequestOptions); }
@DoesServiceRequest private boolean exists(final boolean primaryOnly, QueueRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { opContext = new OperationContext(); } opContext.initialize(); options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient); return ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.existsImpl(primaryOnly, options), options.getRetryPolicyFactory(), opContext); }
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient); options.assertPolicyIfRequired(); options.getRetryPolicyFactory(), opContext);
options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);
@Override public ArrayList<CloudQueueMessage> preProcessResponse(CloudQueue queue, CloudQueueClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } else { // Parse the returned messages ArrayList<CloudQueueMessage> messages = QueueMessageHandler.readMessages( this.getConnection().getInputStream(), queue.shouldEncodeMessage); // Decode the messages if necessary if (options.getEncryptionPolicy() != null) { for (CloudQueueMessage message : messages) { byte[] decryptedMessage = options.getEncryptionPolicy().decryptMessage( message.messageContent, options.requireEncryption()); message.setMessageContent(decryptedMessage); } } return messages; } }