cloudQueue = cloudQueueClient.getQueueReference(queue);
/** * Gets an iterable collection of queues for this queue service client. * * @return An iterable collection of {@link CloudQueue} objects retrieved lazily that * represent the queues in this client. */ @DoesServiceRequest public Iterable<CloudQueue> listQueues() { return this.listQueues(null, QueueListingDetails.NONE, null, null); }
connectionString = String.format(FORMAT_QUEUE_BASE_URI, storageAccountName); StorageCredentials storageCredentials = new StorageCredentialsSharedAccessSignature(sasToken); cloudQueueClient = new CloudQueueClient(new URI(connectionString), storageCredentials); } else { connectionString = String.format(FORMAT_QUEUE_CONNECTION_STRING, storageAccountName, storageAccountKey);
@Test public void testQueueTypesWithStorageUri() throws URISyntaxException, StorageException { CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); StorageUri endpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); CloudQueueClient client = new CloudQueueClient(endpoint, queueClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); StorageUri queueUri = new StorageUri(new URI(endpoint.getPrimaryUri() + "/queue"), new URI( endpoint.getSecondaryUri() + "/queue")); CloudQueue queue = client.getQueueReference("queue"); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); queue = new CloudQueue(queueUri, client.getCredentials()); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); }
@Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) @Test public void testListQueuesAndListQueuesSegmentedLargeNumber() throws URISyntaxException, StorageException { CloudQueueClient qClient = QueueTestHelper.createCloudQueueClient(); int count = 0; String prefix = UUID.randomUUID().toString(); for (CloudQueue queue : qClient.listQueues(prefix)) { assertNotNull(queue); count++; } int totalLimit = 505; if (count < totalLimit) { NumberFormat myFormat = NumberFormat.getInstance(); myFormat.setMinimumIntegerDigits(4); for (int i = 0; i < totalLimit - count; i++) { CloudQueue q = qClient.getQueueReference(prefix + i); q.createIfNotExists(); } } ResultSegment<CloudQueue> segment = qClient.listQueuesSegmented(prefix, QueueListingDetails.NONE, 500, null, null, null); assertTrue(segment.getLength() == 500); assertTrue(segment.getContinuationToken() != null); }
URI sasUri = sasClient.getQueueReference(queue.getName()).getUri(); sasUri = sasClient.getCredentials().transformUri(sasUri); final CloudQueue sasQueue = new CloudQueue(sasUri); (policy.getPermissions().contains(SharedAccessAccountPermissions.LIST))) { assertEquals(sasQueue.getName(), sasClient.listQueues(sasQueue.getName()).iterator().next().getName()); sasClient.listQueues(sasQueue.getName()).iterator().next(); fail(); assertEquals(AccountSasTests.ENUMERATION_ERROR_MESSAGE, ex.getMessage()); assertEquals(sasQueue.getName(), this.queueClient.listQueues(sasQueue.getName()).iterator().next().getName());
@Test public void testQueueClientConstructor() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue1 = qClient.getQueueReference(queueName); assertEquals(queueName, queue1.getName()); assertTrue(queue1.getUri().toString().endsWith(queueName)); assertEquals(qClient, queue1.getServiceClient()); CloudQueue queue2 = new CloudQueue(new URI(QueueTestHelper.appendQueueName(qClient.getEndpoint(), queueName)), qClient.getCredentials()); assertEquals(queueName, queue2.getName()); assertEquals(qClient.getCredentials(), queue2.getServiceClient().getCredentials()); }
int initialCount = 0; String prefix = UUID.randomUUID().toString().toLowerCase(); for (CloudQueue queue : qClient.listQueues(prefix)) { assertNotNull(queue); initialCount++; CloudQueue q = qClient.getQueueReference(prefix + i); q.setMetadata(metadata1); q.create(); for (CloudQueue queue : qClient.listQueues(prefix)) { assertNotNull(queue); count++; CloudQueue q = qClient.getQueueReference(prefix + "a" + i); HashMap<String, String> metadata2 = new HashMap<String, String>(); metadata2.put("tags", q.getName()); for (CloudQueue queue : qClient.listQueues(prefix + "a", QueueListingDetails.METADATA, null, null)) { count++; assertTrue(queue.getMetadata().size() == 1 && queue.getMetadata().get("tags").equals(queue.getName()));
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(); } }
@Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) @Test public void testListQueuesSegmented() throws URISyntaxException, StorageException { CloudQueueClient qClient = QueueTestHelper.createCloudQueueClient(); String prefix = "segment" + UUID.randomUUID().toString().substring(0, 8).toLowerCase(); HashMap<String, String> metadata1 = new HashMap<String, String>(); metadata1.put("ExistingMetadata1", "ExistingMetadataValue1"); for (int i = 0; i < 35; i++) { CloudQueue q = qClient.getQueueReference(prefix + UUID.randomUUID().toString().toLowerCase()); q.setMetadata(metadata1); q.create(); } ResultSegment<CloudQueue> segment1 = qClient.listQueuesSegmented(prefix); assertTrue(segment1.getLength() == 35); ResultSegment<CloudQueue> segment2 = qClient.listQueuesSegmented(prefix, QueueListingDetails.NONE, 5, null, null, null); assertTrue(segment2.getLength() == 5); int totalRoundTrip = 1; while (segment2.getHasMoreResults()) { segment2 = qClient.listQueuesSegmented(prefix, QueueListingDetails.NONE, 5, segment2.getContinuationToken(), null, null); assertTrue(segment2.getLength() == 5); totalRoundTrip++; } assertTrue(totalRoundTrip == 7); ResultSegment<CloudQueue> segment3 = qClient.listQueuesSegmented(prefix, QueueListingDetails.NONE, null, null, null, null); assertTrue(segment3.getLength() == 35); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testSASClientParse() throws StorageException, InvalidKeyException, URISyntaxException { // 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()); policy1.setPermissions(EnumSet.of(SharedAccessQueuePermissions.READ, SharedAccessQueuePermissions.PROCESSMESSAGES, SharedAccessQueuePermissions.ADD, SharedAccessQueuePermissions.UPDATE)); String sasString = this.queue.generateSharedAccessSignature(policy1, null); URI queueUri = new URI("http://myaccount.queue.core.windows.net/myqueue"); CloudQueueClient queueClient1 = new CloudQueueClient(new URI("http://myaccount.queue.core.windows.net/"), new StorageCredentialsSharedAccessSignature(sasString)); CloudQueue queue1 = new CloudQueue(queueUri, queueClient1.getCredentials()); queue1.getName(); CloudQueueClient queueClient2 = new CloudQueueClient(new URI("http://myaccount.queue.core.windows.net/"), new StorageCredentialsSharedAccessSignature(sasString)); CloudQueue queue2 = new CloudQueue(queueUri, queueClient2.getCredentials()); queue2.getName(); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }
@Test public void testCloudStorageAccountClientMethods() throws URISyntaxException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount account = new CloudStorageAccount(cred, false); CloudBlobClient blob = account.createCloudBlobClient(); CloudQueueClient queue = account.createCloudQueueClient(); CloudTableClient table = account.createCloudTableClient(); CloudFileClient file = account.createCloudFileClient(); // check endpoints assertEquals("Blob endpoint doesn't match account", account.getBlobEndpoint(), blob.getEndpoint()); assertEquals("Queue endpoint doesn't match account", account.getQueueEndpoint(), queue.getEndpoint()); assertEquals("Table endpoint doesn't match account", account.getTableEndpoint(), table.getEndpoint()); assertEquals("File endpoint doesn't match account", account.getFileEndpoint(), file.getEndpoint()); // check storage uris assertEquals("Blob endpoint doesn't match account", account.getBlobStorageUri(), blob.getStorageUri()); assertEquals("Queue endpoint doesn't match account", account.getQueueStorageUri(), queue.getStorageUri()); assertEquals("Table endpoint doesn't match account", account.getTableStorageUri(), table.getStorageUri()); assertEquals("File endpoint doesn't match account", account.getFileStorageUri(), file.getStorageUri()); // check creds assertEquals("Blob creds don't match account", account.getCredentials(), blob.getCredentials()); assertEquals("Queue creds don't match account", account.getCredentials(), queue.getCredentials()); assertEquals("Table creds don't match account", account.getCredentials(), table.getCredentials()); assertEquals("File creds don't match account", account.getCredentials(), file.getCredentials()); }
@Category({ CloudTests.class }) @Test public void testGetServiceStats() throws StorageException { CloudQueueClient qClient = QueueTestHelper.createCloudQueueClient(); qClient.getDefaultRequestOptions().setLocationMode(LocationMode.SECONDARY_ONLY); TestHelper.verifyServiceStats(qClient.getServiceStats()); } }
this.queue.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient() .getCredentials().getClass().toString()); queueClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); queueClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000); queueClient.getDefaultRequestOptions().setRetryPolicyFactory(new RetryNoRetry()); .getCredentials().getClass().toString());
/** * Creates an instance of the <code>CloudQueue</code> class using the specified name and client. * * @param queueName * The name of the queue, which must adhere to queue naming rules. The queue name should not include any * path separator characters (/). * Queue names must be lowercase, between 3-63 characters long and must start with a letter or number. * Queue names may contain only letters, numbers, and the dash (-) character. * @param client * A {@link CloudQueueClient} object that represents the associated service client, and that specifies * the endpoint for the Queue service. * @throws URISyntaxException * If the resource URI constructed based on the queueName is invalid. * @throws StorageException * If a storage service error occurred. * @see <a href="http://msdn.microsoft.com/en-us/library/azure/dd179349.aspx">Naming Queues and Metadata</a> */ protected CloudQueue(final String queueName, final CloudQueueClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("queueName", queueName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), queueName); this.name = queueName; this.queueServiceClient = client; this.shouldEncodeMessage = true; }
/** * Retrieves the current {@link ServiceProperties} for the given storage service. This includes Logging, * HourMetrics, MinuteMetrics and CORS configurations. * * @return the {@link ServiceProperties} object representing the current configuration of the service. * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final ServiceProperties downloadServiceProperties() throws StorageException { return this.downloadServiceProperties(null /* options */, null /* opContext */); }
/** * Queries the service for the {@link ServiceStats}. * * @return {@link ServiceStats} for the given storage service * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public ServiceStats getServiceStats() throws StorageException { return this.getServiceStats(null /* options */, null /* 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); QueueRequestOptions.populateRequestOptions(modifiedOptions, client.getDefaultRequestOptions()); QueueRequestOptions.applyDefaults(modifiedOptions); return modifiedOptions; }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }